Function PositionEntity(ent:Int, X:Float, Y:Float, Z:Float)
	Local obj:B3DEntity = B3DEntity(HandleToObject(ent))
	If obj <> Null
		Select obj._typ
			Case ET_CAMERA		; Camera(obj.obj).SetPosition(x, y, 0-z)
			Case ET_ENTITY		; Entity(obj.obj).SetPosition(x, y, 0-z)
			Case ET_SCENENODE	; SceneNode(obj.obj).SetPosition(x, y, 0-z)
			Case ET_LIGHT		; Light(obj.obj).SetPosition(x, y, 0-z)
		End Select
	End If
End Function


Function MoveEntity(ent:Int, x:Float, y:Float, z:Float, relativeTo:Int = TS_LOCAL)
	Local obj:B3DEntity = B3DEntity(HandleToObject(ent))
	
	Select obj._typ
		Case ET_CAMERA			; Camera(obj.obj).moveRelative(bVector3.Create(x, y, 0-z))
		Case ET_ENTITY			; Entity(obj.obj).translate(x, y, 0-z, relativeTo)
		Case ET_SCENENODE		; SceneNode(obj.obj).translate(x, y, 0-z, relativeTo)
	End Select
End Function


Function TurnEntity(ent:Int, x:Float, y:Float, z:Float, relativeTo:Int = TS_LOCAL)
	Local obj:B3DEntity = B3DEntity(HandleToObject(ent))
	
	Select obj._typ
		Case ET_CAMERA
			Camera(obj.obj).pitch(x)
			Camera(obj.obj).yaw(y)
			Camera(obj.obj).roll(z)
			
		Case ET_SCENENODE
			SceneNode(obj.obj).pitch(x, relativeTo)
			SceneNode(obj.obj).yaw(y, relativeTo)
			SceneNode(obj.obj).roll(z, relativeTo)
			
		Case ET_ENTITY
			Entity(obj.obj).Turn(x, y, z, relativeTo)
	End Select
End Function


Function CreatePivot:Int()
	Local ent:B3DEntity = New B3DEntity
	Local node:SceneNode = getBlitz3D()._rootscenenode.createChildSceneNode()
	Local nme:String = node.getName()
	
	ent.obj		= node
	ent._typ	= ET_SCENENODE
	
	getBlitz3D()._AddEntity(nme, ent)
	
	Return HandleFromObject(ent)
End Function


Function EntityParent(ent:Int, parent:Int)
	Local e:B3DEntity = B3DEntity(HandleToObject(ent))
	Local p:B3DEntity = B3DEntity(HandleToObject(parent))
	
	Select p._typ
		Case ET_SCENENODE
			Select e._typ
				Case ET_CAMERA		; SceneNode(p.obj).attachObject(Camera(e.obj))
			End Select
	End Select
End Function


Function EntityX:Float(ent:Int)
	Local obj:B3DEntity = B3DEntity(HandleToObject(ent))
	Local x:Float = 0.0
	
	Select obj._typ
		Case ET_LIGHT		; x = Light(obj.obj).GetPosition().x
		Case ET_CAMERA		; x = Camera(obj.obj).GetPosition().x
		Case ET_SCENENODE	; x = SceneNode(obj.obj).GetPosition().x
		Case ET_ENTITY		; x = Entity(obj.obj).GetPosition().x
	End Select
	
	Return x
End Function


Function EntityY:Float(ent:Int)
	Local obj:B3DEntity = B3DEntity(HandleToObject(ent))
	Local y:Float = 0.0
	
	Select obj._typ
		Case ET_LIGHT		; y = Light(obj.obj).GetPosition().y
		Case ET_CAMERA		; y = Camera(obj.obj).GetPosition().y
		Case ET_SCENENODE	; y = SceneNode(obj.obj).GetPosition().y
		Case ET_ENTITY		; y = Entity(obj.obj).GetPosition().y
	End Select
	
	Return y
End Function


Function EntityZ:Float(ent:Int)
	Local obj:B3DEntity = B3DEntity(HandleToObject(ent))
	Local z:Float = 0.0
	
	Select obj._typ
		Case ET_LIGHT		; z = Light(obj.obj).GetPosition().z
		Case ET_CAMERA		; z = Camera(obj.obj).GetPosition().z
		Case ET_SCENENODE	; z = SceneNode(obj.obj).GetPosition().z
		Case ET_ENTITY		; z = Entity(obj.obj).GetPosition().z
	End Select
	
	Return z
End Function


Function PointEntity(ent:Int, target:Int)
	Local e:B3DEntity = B3DEntity(HandleToObject(ent))
	Local t:B3DEntity = B3DEntity(HandleToObject(target))
	
	Local vec3:bVector3 = bVector3.NullVec()
	
	Select e._typ
		Case ET_LIGHT
			Select t._typ
				Case ET_SCENENODE
					vec3 = SceneNode(t.obj).GetPosition()
					Light(e.obj).setDirection(vec3.getX(), vec3.getY(), vec3.getZ())
					
				Case ET_ENTITY
					vec3 = Entity(t.obj).GetPosition()
					Light(e.obj).setDirection(vec3.getX(), vec3.getY(), vec3.getZ())
					
				Case ET_CAMERA
					vec3 = Camera(t.obj).GetPosition()
					Light(e.obj).setDirection(vec3.getX(), vec3.getY(), vec3.getZ())
					
				Case ET_LIGHT
					vec3 = Light(t.obj).GetPosition()
					Light(e.obj).setDirection(vec3.getX(), vec3.getY(), vec3.getZ())
					
			End Select
			
		Case ET_SCENENODE
		
		Case ET_ENTITY
		
		Case ET_CAMERA
		
		Case ET_LIGHT
	End Select
End Function


Function FreeEntity(ent:Int)
	Local obj:B3DEntity = B3DEntity(HandleToObject(ent))
	
	Select obj._typ
		Case ET_CAMERA		; _blitzogre3d._scenemanager.destroyCamera(Camera(obj.obj))
		Case ET_ENTITY		; _blitzogre3d._scenemanager.destroyEntity(Entity(obj.obj))
		Case ET_LIGHT		; _blitzogre3d._scenemanager.destroyLight(Light(obj.obj))
		Case ET_SCENENODE	; _blitzogre3d._scenemanager.destroySceneNode(SceneNode(obj.obj))
	End Select
End Function


Function EntityShadows(ent:Int, enable:Byte = False)
	Local obj:B3DEntity = B3DEntity(HandleToObject(ent))
	
	Select obj._typ
		Case ET_ENTITY		; Entity(obj.obj).setCastShadows(enable)
		Case ET_LIGHT		; Light(obj.obj).setCastShadows(enable)
	End Select
End Function


Function CopyEntity:Int(ent:Int)
	Local obj:B3DEntity = B3DEntity(HandleToObject(ent))
	Local c:B3DEntity = New B3DEntity
	
	Select obj._typ
		Case ET_ENTITY
			Local e:Entity = Entity(obj.obj).clone();
			o_attachObject(getBlitz3D()._rootscenenode.createChildSceneNode()._ptr, e._ptr)
			c.obj 	= e
			c._typ	= e._typ
			getBlitz3D()._AddEntity(e.getName(), c)
	End Select
	
	Return HandleFromObject(c)
End Function


Function DynamicEntity(ent:Int, collisionShapeType:Int = CS_BOX, mass:Float = 1.0, playerControlled:Byte = False)
	If getPhysicsHandle() = Null Then Physics()
	
	Local b:B3DEntity 			= B3DEntity(HandleToObject(ent))
	Local e:Entity 				= Entity(b.obj)
	Local aab:AxisAlignedBox 	= e.getBounds()
	Local sze:bVector3			= aab.GetSize()
	
	Local _size:bVector3 = bVector3.Create(sze.GetX(), sze.GetY(), sze.GetZ())
	Local _pos:bVector3		= bVector3.Create(e.GetPosition().getX(), e.GetPosition().getY(), e.GetPosition().getZ())
	
	b._rigidbody = getPhysicsHandle().createRigidBody(collisionShapeType, mass, playerControlled, _size, _pos)
End Function


